package com.lijinjiang.json;

import com.alibaba.fastjson2.JSON;

/**
 * @ClassName Demo01
 * @Description TODO
 * @Author Li
 * @Date 2022/10/15 13:11
 * @ModifyDate 2022/10/15 13:11
 * @Version 1.0
 */
public class Demo01 {
    public static void main(String[] args) {
        // 1.将Java对象转成JSON字符串
        User user = new User(1,"张三","123456");
        String str = JSON.toJSONString(user);
        System.out.println(str); // {"id":1,"password":"123456","username":"张三"}

        // 2.将JSON字符串转成Java对象
        User obj = JSON.parseObject("{\"id\":2,\"password\":\"123456\",\"username\":\"李四\"}", User.class);
        System.out.println(obj);
    }
}
